home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-3.98 / bfd.mips / trad-core.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-23  |  5.4 KB  |  180 lines

  1. /* BFD back end for traditional Unix core files (U-area and raw sections)
  2.    Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
  3.    Written by John Gilmore of Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* This file does not define a particular back-end, but it defines routines
  22.    that can be used by other back-ends.  */
  23. #include <sysdep.h>
  24. #include "bfd.h"
  25. #include <stdio.h>
  26. #include "libbfd.h"
  27.  
  28. #include "libaout.h"           /* BFD a.out internal data structures */
  29.  
  30. #include <sys/types.h>
  31. #include <sys/param.h>
  32. #include <sys/dir.h>
  33. #include <signal.h>
  34. #include <machine/reg.h>
  35.  
  36. #include <sys/user.h>        /* After a.out.h  */
  37. #include <sys/file.h>
  38. #include <sys/stat.h>
  39.  
  40. #include <errno.h>
  41.  
  42. /* need this cast b/c ptr is really void * */
  43. #define core_hdr(bfd) (((struct core_data *) (bfd->tdata))->hdr)
  44. #define core_datasec(bfd) (((struct core_data *) ((bfd)->tdata))->data_section)
  45. #define core_stacksec(bfd) (((struct core_data*)((bfd)->tdata))->stack_section)
  46. #define core_regsec(bfd) (((struct core_data *) ((bfd)->tdata))->reg_section)
  47. #define core_upage(bfd) (((struct core_data *) ((bfd)->tdata))->upage)
  48.  
  49. /* These are stored in the bfd's tdata */
  50. struct core_data {
  51.   struct user *upage;             /* core file header */
  52.   asection *data_section;
  53.   asection *stack_section;
  54.   asection *reg_section;
  55. };
  56.  
  57. /* ARGSUSED */
  58. bfd_target *
  59. trad_unix_core_file_p (abfd)
  60.      bfd *abfd;
  61. {
  62. #if HOST_SYS == SUN4_SYS
  63.   return 0;
  64. #else
  65.   int val;
  66.   char *rawptr;
  67.   struct user u;
  68.   unsigned int reg_offset, fp_reg_offset;
  69.  
  70.   /* 4.2-style (and perhaps also sysV-style) core dump file.  */
  71.  
  72.   val = bfd_read ((void *)&u, 1, sizeof u, abfd);
  73.   if (val != sizeof u)
  74.     return 0;            /* Too small to be a core file */
  75.  
  76.   /* Sanity check perhaps??? */
  77.   if (u.u_dsize > 0x1000000)    /* Remember, it's in pages... */
  78.     return 0;
  79.   if (u.u_ssize > 0x1000000)
  80.     return 0;
  81.   /* Check that the size claimed is no greater than the file size. FIXME. */
  82.  
  83.   /* OK, we believe you.  You're a core file (sure, sure).  */
  84.  
  85.   /* Allocate both the upage and the struct core_data at once, so
  86.      a single free() will free them both.  */
  87.   rawptr = (char *)zalloc (sizeof (u) + sizeof (struct core_data));
  88.   if (rawptr == NULL) {
  89.     bfd_error = no_memory;
  90.     return 0;
  91.   }
  92.   
  93.   set_tdata (abfd, (struct core_data *)rawptr);
  94.   core_upage (abfd) = (struct user *)(rawptr + sizeof (struct core_data));
  95.   *core_upage (abfd) = u;        /* Save that upage! */
  96.  
  97.   /* create the sections.  This is raunchy, but bfd_close wants to reclaim
  98.      them */
  99.   core_stacksec (abfd) = (asection *) zalloc (sizeof (asection));
  100.   if (core_stacksec (abfd) == NULL) {
  101. loser:
  102.     bfd_error = no_memory;
  103.     free ((void *)rawptr);
  104.     return 0;
  105.   }
  106.   core_datasec (abfd) = (asection *) zalloc (sizeof (asection));
  107.   if (core_datasec (abfd) == NULL) {
  108. loser1:
  109.     free ((void *)core_stacksec (abfd));
  110.     goto loser;
  111.   }
  112.   core_regsec (abfd) = (asection *) zalloc (sizeof (asection));
  113.   if (core_regsec (abfd) == NULL) {
  114. loser2:
  115.     free ((void *)core_datasec (abfd));
  116.     goto loser1;
  117.   }
  118.  
  119.   core_stacksec (abfd)->name = ".stack";
  120.   core_datasec (abfd)->name = ".data";
  121.   core_regsec (abfd)->name = ".reg";
  122.  
  123.   core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
  124.   core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
  125.   core_regsec (abfd)->flags = SEC_ALLOC;
  126.  
  127.   core_datasec (abfd)->size =  NBPG * u.u_dsize;
  128.   core_stacksec (abfd)->size = NBPG * u.u_ssize;
  129.   core_regsec (abfd)->size = NBPG * UPAGES;  /* Larger than sizeof struct u */
  130.  
  131.   /* What a hack... we'd like to steal it from the exec file,
  132.      since the upage does not seem to provide it.  FIXME.  */
  133.   core_datasec (abfd)->vma = TEXT_START_ADDR + (NBPG * u.u_tsize);
  134.   core_stacksec (abfd)->vma = STACK_END_ADDR - (NBPG * u.u_ssize);
  135.   core_regsec (abfd)->vma = -1;
  136.  
  137.   core_datasec (abfd)->filepos = NBPG * UPAGES;
  138.   core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize;
  139.   core_regsec (abfd)->filepos = 0;    /* Register segment is the upage */
  140.  
  141.   /* Align to word at least */
  142.   core_stacksec (abfd)->alignment_power = 2;
  143.   core_datasec (abfd)->alignment_power = 2;
  144.   core_regsec (abfd)->alignment_power = 2;
  145.  
  146.   abfd->sections = core_stacksec (abfd);
  147.   core_stacksec (abfd)->next = core_datasec (abfd);
  148.   core_datasec (abfd)->next = core_regsec (abfd);
  149.   abfd->section_count = 3;
  150.  
  151.   return abfd->xvec;
  152. #endif
  153. }
  154.  
  155. char *
  156. trad_unix_core_file_failing_command (abfd)
  157.      bfd *abfd;
  158. {
  159.   if (*core_upage (abfd)->u_comm)
  160.     return core_upage (abfd)->u_comm;
  161.   else
  162.     return 0;
  163. }
  164.  
  165. /* ARGSUSED */
  166. int
  167. trad_unix_core_file_failing_signal (ignore_abfd)
  168.      bfd *ignore_abfd;
  169. {
  170.   return -1;        /* FIXME, where is it? */
  171. }
  172.  
  173. /* ARGSUSED */
  174. boolean
  175. trad_unix_core_file_matches_executable_p  (core_bfd, exec_bfd)
  176.      bfd *core_bfd, *exec_bfd;
  177. {
  178.   return true;        /* FIXME, We have no way of telling at this point */
  179. }
  180.